package cx.cxyxj.sso.auth.client1;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;


@RestController
public class HelloController {


    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/hello")
    public String hello() throws JsonProcessingException {

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String s = new ObjectMapper().writeValueAsString(authentication);
        return s;
    }
    /**
     * OAuth 登录回调地址
     * @param code
     * @return
     */
    @GetMapping("/codeLogin")
    public String hello(String code,String state) {
        System.out.println("code = "+code);
        if (code != null) {
            MultiValueMap<String, String> map = new LinkedMultiValueMap<>();

            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            //
        }
        return "EROOR";
    }


}
